﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _01各种知识点
{
    class Program
    {
        static void Main(string[] args)
        {
            /*
             Person p1 = new Person(); 
            p1[3, 5] = "hello";//set
            string s = p1[1, 2];//get
            Console.WriteLine(s);
            Console.ReadKey();
            */

            /*
            Dog d = new Dog();
            d["hello"] = 5;
            int i = d["yeyey"];
            Console.WriteLine(i);
            Console.ReadKey();
            */
            /* 扩展方法
            string e = "abc@126.com";
            bool b= Person.IsEmail(e);
            Console.WriteLine(b);
            Console.WriteLine(e.IsEmail());
            Console.ReadKey();
            */
            string s = "abc";
            string s1 = Person.Repeat(s, 3);
            Console.WriteLine(s1);
            Console.WriteLine(s1.Repeat(5));
            Console.WriteLine();
            Console.ReadKey();

            SqlConnection conn = new SqlConnection();
            conn.Test("select * from ");

        }

        //索引器
         
        class Dog
        {
            public int this[string s]
            {
                get {
                    return 888;
                }
                set {
                    Console.WriteLine("s的值是"+s);
                }
            }
        }


    }

    static class Person
    {
        /*
        public string this[int x,int y]
        {
            get
            {
                return "" + x + y;
            }
            set
            {
                Console.WriteLine("x=" + x +";y="+y);
            }
        }
        */
        public static bool IsEmail(this string s) //表示给string 扩展一个IsEmail方法
        {
            return s.Contains("@");
        }
        public static string Repeat(this string s, int count)
        {
            string result = "";
            for (int i = 0; i < count; i++)
            {
                result = result + s; 
            }
            return result;
        }
        public static void Test(this SqlConnection conn,string sql)
        {
            //...
        }
    }
}
